<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>Leaflet debug page</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="Leaflet/src/Leaflet.js"></script>
    <link rel="stylesheet" href="Leaflet/dist/leaflet.css" />
	<style type="text/css">
		html,body{
			height:100%
		}
	</style>
</head>
<body>
    <div id="tb">
    <div>
<!--     &nbsp;小区：&nbsp; -->
<%--  		<input class="easyui-combobox" id="frontId" multiple=true name="frontId" style="width:400px" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/frontId.do'" /> --%>
   		&nbsp;类型：&nbsp;
 		<select id="Type" class="easyui-combotree" style="width:135px;" data-options="panelHeight:'auto', panelMaxHeight:'240px'" multiple></select> 
   		&nbsp;小区：&nbsp;
   		<select id="frontId" class="easyui-combotree" style="width:140px;" data-options="panelHeight:'auto', panelMaxHeight:'240px'" multiple></select>
 		
 		&nbsp;&nbsp;<input name="view" type="button" id="view" value="查看" onclick="view(0);"/>  
 		&nbsp;&nbsp;<input name="view" type="button" id="view" value="刷新" onclick="view(0);"/>  
 	</div><p>
 	<div id="stationphoto" style="float:left;width:25px;height:41px;"></div>
 	<div style="float:left;">&nbsp;&nbsp;车站&nbsp;&nbsp;&nbsp;</div>
 	<div id="frontIdphoto" style="float:left;width:25px;height:41px;"></div>
 	<div style="float:left;">&nbsp;&nbsp;前置机&nbsp;&nbsp;&nbsp;</div>
 	<div id="inf_frontIdphoto" style="float:left;width:25px;height:41px;"></div>
 	<div style="float:left;">&nbsp;&nbsp;未处理干扰前置机&nbsp;&nbsp;&nbsp;</div>
 	<div id="yidongphoto" style="float:left;width:25px;height:41px;"></div>
 	<div style="float:left;">&nbsp;&nbsp;移动基站&nbsp;&nbsp;&nbsp;</div>
 	<div id="liantongphoto" style="float:left;width:25px;height:41px;"></div>
 	<div style="float:left;">&nbsp;&nbsp;联通基站&nbsp;&nbsp;&nbsp;</div>
 	<div id="Historyinterferencephoto" style="float:left;width:25px;height:41px;"></div>
 	<div style="float:left;">&nbsp;&nbsp;历史干扰源&nbsp;&nbsp;&nbsp;</div>
   </div><p>
   <div id="map" style="width:100%;height:80%;border: 1px solid #ccc;"></div>
   
   <script>
 	  window.onload = function (){  
       var bigImg = document.createElement("img");     //创建一个img元素
       bigImg.src="${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-black.png";   //给img元素的src属性赋值
       var myp = document.getElementById('frontIdphoto'); //获得dom对象
       myp.appendChild(bigImg);    //为dom添加子元素img
       
       var bigImg2 = document.createElement("img");     //创建一个img元素
       bigImg2.src="${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon.png";   //给img元素的src属性赋值
       var myp2 = document.getElementById('yidongphoto'); //获得dom对象
       myp2.appendChild(bigImg2);    //为dom添加子元素img
       
       var bigImg3 = document.createElement("img");     //创建一个img元素
       bigImg3.src="${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-violet.png";   //给img元素的src属性赋值
       var myp3 = document.getElementById('liantongphoto'); //获得dom对象
       myp3.appendChild(bigImg3);    //为dom添加子元素img
       
       var bigImg4 = document.createElement("img");     //创建一个img元素
       bigImg4.src="${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/timg.png";   //给img元素的src属性赋值
       var myp4 = document.getElementById('stationphoto'); //获得dom对象
       myp4.appendChild(bigImg4);    //为dom添加子元素img
       
       var bigImg5 = document.createElement("img");     //创建一个img元素
       bigImg5.src="${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/inf.png";   //给img元素的src属性赋值
       var myp5 = document.getElementById('Historyinterferencephoto'); //获得dom对象
       myp5.appendChild(bigImg5);    //为dom添加子元素img
       
       var bigImg6 = document.createElement("img");     //创建一个img元素
       bigImg6.src="${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-red.png";   //给img元素的src属性赋值
       var myp6 = document.getElementById('inf_frontIdphoto'); //获得dom对象
       myp6.appendChild(bigImg6);    //为dom添加子元素img
       
       var firstInTag=1;
       
   };
  
   var osmUrl = '/MyTiles/{z}/{x}/{y}.png',
   osmAttrib = '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
   osm = L.tileLayer(osmUrl, {maxZoom: 15, attribution: osmAttrib});
   var map = L.map('map')
        	.setView([23.16,113.23],12)
        	.addLayer(osm);
   var FrontId;
  // var PiontType="车站,前置机,移动基站,联通基站";
   var layers=[];
   var myIcon = L.icon({
	    iconUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-black.png",
	    iconRetinaUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-2x-black.png",
	   // shadowUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-shadow.png",
	    iconSize:[23,30],
	   // iconAnchor:[12,65],
	    popupAnchor:[1,-34],
	    tooltipAnchor:[16,-28],
	   // shadowSize:[65,65] 
	});
   var yidong = L.icon({
	    iconUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon.png",
	    iconRetinaUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-2x.png",
	    shadowUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-shadow.png",
	    iconSize:[30,49],
	    iconAnchor:[12,41],
	    popupAnchor:[1,-34],
	    tooltipAnchor:[16,-28],
	    shadowSize:[41,41] 
	});
   var liantong = L.icon({
	    iconUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-violet.png",
	    iconRetinaUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-2x-violet.png",
	    shadowUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-shadow.png",
	    iconSize:[30,49],
	    iconAnchor:[12,41],
	    popupAnchor:[1,-34],
	    tooltipAnchor:[16,-28],
	    shadowSize:[41,41] 
	});
   var station = L.icon({
	    iconUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/timg.png",
	    iconRetinaUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/timg-2x.png",
	   // shadowUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-shadow.png",
	    iconSize:[30,30],
	    //iconAnchor:[12,41],
	    popupAnchor:[1,-34],
	    tooltipAnchor:[16,-28],
	   // shadowSize:[41,41] 
	});
   
   var historyInterferenceIcon = L.icon({
	    iconUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/inf.png",
	    iconRetinaUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/inf-2x.png",
	   // shadowUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-shadow.png",
	    iconSize:[40,32],
	   // iconAnchor:[12,65],
	    popupAnchor:[1,-34],
	    tooltipAnchor:[16,-28],
	   // shadowSize:[65,65]  
	});
   
   var inf_frontIdIcon = L.icon({
	    iconUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-red.png",
	    iconRetinaUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-icon-2x-red.png",
	    //shadowUrl:"${pageContext.request.contextPath}/page/page_interference/Leaflet/dist/images/marker-shadow.png",
	    iconSize:[23,30],
	   // iconAnchor:[12,65],
	    popupAnchor:[1,-34],
	    tooltipAnchor:[16,-28],
	    //shadowSize:[65,65] 
	});
   
   function formatDatebox(value) {
		var datetimeType = "";
		var date =new Date(parseInt(value));
		datetimeType = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate() +" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+" "+date.getMilliseconds();
		if(datetimeType != "NaN-NaN-NaN NaN:NaN:NaN NaN")
			return datetimeType;
	}

   function view(FirstTag){
	   
    var myGroup=L.layerGroup(layers);
	map.addLayer(myGroup);
	myGroup.clearLayers();
	if(FirstTag==1) {
	   	FrontId=$("#frontId").combobox("getText");
	   	PiontType="车站,前置机,移动基站,联通基站";
	} else {
	   	FrontId=$("#frontId").combobox("getText");
	   	PiontType=$("#Type").combobox("getText");
	}

   	
   	//20190415
   	if(PiontType==""){
   		console.log("----------1---------------------------")
   		$.messager.alert("系统提示","请先选择类型！");
   		
   		//PiontType = ["车站", "前置机", "移动基站", "联通基站"];  
   	} 
   /* 	else if(firstInTag==1) {
   		PiontType="车站,前置机,移动基站,联通基站";
   		firstInTag=0;
   	} */

   	else{
   		console.log("----------2-------------------------")   		
   		console.log(PiontType);
   		$.post("${pageContext.request.contextPath}/interferencequery/bsstation.do",{frontId:FrontId,piontType:PiontType},
           		function(result){
   			       	var frontIdinfo=result.frontId;
   			       	var bsStationinfo=result.bsStation;
   			       	var rsStationinfo=result.rsStation;
   			       	var unsettledFrontIdinfo=result.unsettledFrontId;
   			       	var historyInterferenceinfo=result.historyInterference;
   			       	var tmplat;
   			       	var tmplon;
   			       	for(var i=0;i<frontIdinfo.length;i++){
	   			       	var Title="前置机名:"+frontIdinfo[i].BSName;
	   			       	var lat=frontIdinfo[i].latitude;
	   			       	var lon=frontIdinfo[i].longitude;
	   			       	tmplat=lat;
	   			        tmplon=lon;
	   			        var tag = 0;
	   			        for(var j=0;j<unsettledFrontIdinfo.length;j++){
	   			        	var unsetFrontIdinfo= unsettledFrontIdinfo[j];
	   			        	for(var k=0; k<unsetFrontIdinfo.length; k++) {	   			        	   			        	
		   			        	if(frontIdinfo[i].frontProcessorId==unsetFrontIdinfo[k].frontId) {
		   			        		tag = 1;
		   			        		if(unsetFrontIdinfo[k].disposed==0) {
			   			        		Title=Title+"<br / >"+" 告警级别: "+unsetFrontIdinfo[k].alarmLevel+" 时间: "+formatDatebox(unsetFrontIdinfo[k].timeBegin)+"--"+formatDatebox(unsetFrontIdinfo[k].timeEnd)+" 干扰类型: "+unsetFrontIdinfo[k].infType+" 处理情况: 未处理";
		   			        		} else {
			   			        		Title=Title+"<br / >"+" 告警级别: "+unsetFrontIdinfo[k].alarmLevel+" 时间: "+formatDatebox(unsetFrontIdinfo[k].timeBegin)+"--"+formatDatebox(unsetFrontIdinfo[k].timeEnd)+" 干扰类型: "+unsetFrontIdinfo[k].infType+" 处理情况: 已处理";

		   			        		}
		   			        	}	   			        	
	   			        	}
	   			        }
	   			        var finalIcon = "";
	   			        if(tag==1) {
	   			        	finalIcon = inf_frontIdIcon;
	   			        } else {
	   			        	finalIcon = myIcon;
	   			        }
	   			        var markerStatic = new L.Marker([lon,lat], {
	   			           draggable: false,
	   			           title: Title,
	   			           icon: finalIcon
	   			   		});   
	   			        layers.push(markerStatic);
	   			   		map.addLayer(markerStatic);
	   			   		//markerStatic.bindTooltip("my tooltip text").openTooltip();
	   			        markerStatic.bindPopup(Title);
   			       	}
   			       	if(typeof(tmplon)!="undefined"&&typeof(tmplat)!="undefined") {
   			       		map.setView([tmplon,tmplat],12);
   			       	}
   			     for(var c=0;c<rsStationinfo.length;c++){
   			    	 var rsinfo=rsStationinfo[c];
   			    	 for(var d=0;d<rsinfo.length;d++){
	   			       	var Title1=rsinfo[d].rsName;
	   			       	var lat=rsinfo[d].latitude;
	   			       	var lon=rsinfo[d].longitude;
	   			       	tmplat_rs=lat;
	   			        tmplon_rs=lon;
	   			        var markerStatic = new L.Marker([lon,lat], {
	   			           draggable: false,
	   			           title: Title,
	   			    	    icon:station
	   			   		});
	   			  		//L.tooltip(direction: top,layers);
	   			        layers.push(markerStatic);
	   			   		map.addLayer(markerStatic);
	   			       // markerStatic.bindPopup(Title1);
	   			  	 	markerStatic.bindTooltip(Title1,{direction: "top",permanent: true}).openTooltip();
   			  	     }
				  }
   			  for(var n=0;n<historyInterferenceinfo.length;n++){
			    	 var hisInterferenceinfo=historyInterferenceinfo[n];
			    	 for(var m=0;m<hisInterferenceinfo.length;m++){
	   			       //	var Title2=hisInterferenceinfo[m].rsName;
	   			       var position=hisInterferenceinfo[m].sourcePosition.split(",");
	   			       	var lat=position[0];
	   			       	var lon=position[1];
	   			       	tmplat_his=lat;
	   			        tmplon_his=lon;
	   			        var markerStatic = new L.Marker([lon,lat], {
	   			           draggable: false,
	   			           //title: Title,
	   			    	    icon:historyInterferenceIcon
	   			   		});
	   			  		//L.tooltip(direction: top,layers);
	   			        layers.push(markerStatic);
	   			   		map.addLayer(markerStatic);
	   			       // markerStatic.bindPopup(Title1);
	   			  	 //	markerStatic.bindTooltip(Title1,{direction: "top",permanent: true}).openTooltip();
			  	     }
				  }
   			     
   			        for(var j=0;j<bsStationinfo.length;j++){
   			        	var tmpinfo=bsStationinfo[j];
   			        	for(var k=0;k<tmpinfo.length;k++){
   			        		var Title="";
   			        		if(tmpinfo[k].MNC==0){
   			        			Title=Title+"基站归属:移动基站"+" 位置:"+tmpinfo[k].address;
   			        			var lat=tmpinfo[k].latitude;
   	   		   			       	var lon=tmpinfo[k].longitude;
   	   		   			        var markerStatic = new L.Marker([lat,lon], {
   	   		   			           draggable: false,
   	   		   			           title: Title,
   	   		   			 		   icon:yidong
   	   		   			   		}); 
   	   		   			        layers.push(markerStatic);
   	   		   			   		map.addLayer(markerStatic);
   	   		   			        markerStatic.bindPopup(Title);
   			        		}
   			        		if(tmpinfo[k].MNC==1){
   			        			Title=Title+"基站归属:联通基站"+" 位置:"+tmpinfo[k].address;
   			        			var lat=tmpinfo[k].latitude;
   	   		   			       	var lon=tmpinfo[k].longitude;
   	   		   			        var markerStatic = new L.Marker([lat,lon], {
   	   		   			           draggable: false,
   	   		   			           title: Title,
   	   		   			           icon:liantong   	   		   			        
   	   		   			   		}); 
   	   		   			        layers.push(markerStatic);
   	   		   			   		map.addLayer(markerStatic);
   	   		   			        markerStatic.bindPopup(Title);
   			        		}
   			        			
   			        	}
			       	} 
   			    	},"json");
   	} 
   }
                
  
   $(function(){
	   
	   view(1);
	   $('#frontId').combotree({		 
		    url:'${pageContext.request.contextPath}/networkanalysis/frontId.do'
		 })
		 
	   $('#Type').combotree('loadData', [{id:'1000', text:'全选', children:[
			 {id:'1', text:'车站'},
			 {id:'2', text:'前置机'},
			 {id:'3', text:'移动基站'},
			 {id:'4', text:'联通基站'},
			 {id:'5', text:'历史干扰源'}]}]);
		 
   });
        </script>
</body>
</html>
